package com.game.base.app.base;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

/**
 * 模拟activity方法的view处理父类
 * Created by Su on 2018/12/13.
 */
public abstract class BasePanel<T extends ViewDataBinding> {
    protected Activity activity;
    private Context context;
    protected T binding;

    public BasePanel(Activity activity) {
        this.activity = activity;
        initBaseData();
    }

    public BasePanel(Activity activity, Context context) {
        this.activity = activity;
        this.context = context;
        initBaseData();
    }

    public Activity getActivity() {
        return activity;
    }

    public Context getContext() {
        return context;
    }

    /**
     * 获取布局文件
     */
    protected abstract int getLayoutId();

    /**
     * 初始化基础数据
     */
    private void initBaseData() {
        binding = DataBindingUtil.inflate(LayoutInflater.from(activity), getLayoutId(), null, false);
    }

    public View getContentView() {
        return binding.getRoot();
    }

    public void onDestroy() {
        activity = null;
        context = null;
    }
}
